
<template>
    <div id="addgoods"> 
        商品名<input type="text" v-model="name"><br>
        价格<input type="text" v-model="price"><br>
        商品图片<input type="file" @change="get_file($event)"><br>
        <input type="button" value="添加" @click="addgoods()">
    </div>
</template>
<script>
import axios from "axios"
export default {
    name:"addgoods",
    data(){
        return{
            name:"",
            price:"",
        }
    },methods:{
        get_file(event){
            this.file = event.target.files[0]
        },
        addgoods(){
            var data = new FormData();
            data.append("name",this.name)
            data.append("price",this.price)
            data.append('pic',this.file)
            axios({
                url:"http://127.0.0.1:8000/addgoods",
                method:"post",
                data:data,
            }).then(res=>{
                console.log(res)
                if(res.data.code==200){
                    alert('添加成功')
                }
            })
        }
    }
}
</script>
<style>

</style>